package com.web.mall.service.impl;

import com.web.mall.mapper.TbTypeTemplateMapper;
import com.web.mall.pojo.TbTypeTemplate;
import com.web.mall.pojogroup.TbSpecification;
import com.web.mall.service.TemplateManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

@Service
public class TemplateManagerServiceImpl implements TemplateManagerService {

    @Autowired
    private TbTypeTemplateMapper tbTypeTemplateMapper;

    @Override
    public List<TbTypeTemplate> findTemplateList() {
        return tbTypeTemplateMapper.selectByExample(null);
    }

    @Override
    public List<TbTypeTemplate> queryTemplate() {
        return tbTypeTemplateMapper.selectByExample(null);
    }

    @Override
    public TbTypeTemplate findTbTypeTemplateById(Long id) {
        return null;
    }


    @Override
    public boolean deleteTemplate(Long id) {
        if(id!=null){
            tbTypeTemplateMapper.deleteByPrimaryKey(id);
            return true;
        }else {
            return false;
        }
    }

    @Override
    public boolean saveTemplate(TbTypeTemplate tbTypeTemplate) {
        //判断 brand id
        if(ObjectUtils.isEmpty(tbTypeTemplate.getId())){
            tbTypeTemplateMapper.insert(tbTypeTemplate);
        }else {
            tbTypeTemplateMapper.updateByPrimaryKey(tbTypeTemplate);
        }
        return true;
    }

    @Override
    public TbTypeTemplate findTemplateById(Long id) {
        return tbTypeTemplateMapper.selectByPrimaryKey(id);
    }
}
